/*
* Copyright (c) 2025 Shenzhen Kaihong Digital Industry Development Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include "MWServer.h"
#include "interfaces/c/mw_server.h"
#include <cstdint>
#include <stdexcept>

namespace OHOS {
namespace OHMW {
MWServer::MWServer(Type type) {
    server_ = ohmw_mw_server_create(static_cast<ohmw_mw_server_type>(type));
    if (server_ == nullptr) {
        throw std::runtime_error("failed to create MWServer");
    }
}

MWServer::~MWServer() {
    if (server_ != nullptr) {
        ohmw_mw_server_destroy(server_);
    }
}

int32_t MWServer::Start() {
    if (server_ == nullptr) {
        return -1;
    }
    return ohmw_mw_server_start(server_);
}

int32_t MWServer::Stop() {
    if (server_ == nullptr) {
        return -1;
    }
    return ohmw_mw_server_stop(server_);
}

bool MWServer::IsRunning(Type type) {
    return ohmw_mw_server_is_running(static_cast<ohmw_mw_server_type>(type));
}
}
}
